home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 9 / develop 9 code / NeoTextBox / Utilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-06  |  3.7 KB  |  143 lines  |  [TEXT/MPS ]

  1. /*****************************************************************************************
  2.  
  3. Utilities.c - utility routines for NTBDemo
  4.  
  5. Written by Bryan K. Ressler (Beaker), 8/30/91
  6.  
  7. *****************************************************************************************/
  8.  
  9. /** INCLUDES ****************************************************************************/
  10. #include "NTBDemo.h"            /* NTBDemo stuff */
  11. #include "NeoTextBox.h"
  12. #include "Utilities.h"
  13.  
  14. /****************************************************************************************/
  15. short JustToRadio(short justification)
  16. {
  17.     switch(justification) {
  18.         case teJustLeft:
  19.             return(kJustLeft);
  20.         case teJustCenter:
  21.             return(kJustCenter);
  22.         case teJustRight:
  23.             return(kJustRight);
  24.         case ntbJustFull:
  25.             return(kJustFull);
  26.     }
  27. }
  28.  
  29. /****************************************************************************************/
  30. short RadioToJust(void)
  31. {
  32.     static short    justifications[4] = { teJustLeft,teJustCenter,teJustRight,ntbJustFull };
  33.     
  34.     return(justifications[gJustRadio - kJustLeft]);
  35. }
  36.  
  37. /****************************************************************************************/
  38. short RadioToFont(void)
  39. {
  40.     short    familyID;
  41.     
  42.     switch(gFontRadio) {
  43.         case kAppFont:
  44.             return(GetAppFont());
  45.         case kTimes:
  46.             GetFNum("\pTimes",&familyID);            /* Zero (sys font) if not present */
  47.             return(familyID);
  48.         case kHelvetica:
  49.             GetFNum("\pHelvetica",&familyID);        /* Zero (sys font) if not present */
  50.             return(familyID);
  51.     }
  52. }
  53.  
  54. /****************************************************************************************/
  55. void SetValue(DialogPtr theDialog,short itemNum,short value)
  56. {
  57.     short    aType;
  58.     Rect    aBox;
  59.     Handle    theItem;
  60.  
  61.     GetDItem(theDialog,itemNum,&aType,&theItem,&aBox);
  62.     SetCtlValue((ControlHandle)theItem,value);
  63. }
  64.  
  65. /****************************************************************************************/
  66. void GetItemRect(DialogPtr theDialog,short itemNum,Rect *box)
  67. {
  68.     short    aType;
  69.     Handle    theItem;
  70.  
  71.     GetDItem(theDialog,itemNum,&aType,&theItem,box);
  72. }
  73.  
  74. /****************************************************************************************/
  75. void UserItem(DialogPtr theDialog,short itemNum,void *theProc)
  76. {
  77.     short    aType;
  78.     Rect    aBox;
  79.     Handle    theItem;
  80.  
  81.     GetDItem(theDialog,itemNum,&aType,&theItem,&aBox);
  82.     SetDItem(theDialog,itemNum,aType,(Handle)theProc,&aBox);
  83. }
  84.  
  85. /****************************************************************************************/
  86. void InvalItem(DialogPtr theDialog,short itemNum,short hInset,short vInset)
  87. {
  88.     short    aType;
  89.     Rect    aBox;
  90.     Handle    theItem;
  91.  
  92.     GetDItem(theDialog,itemNum,&aType,&theItem,&aBox);
  93.     InsetRect(&aBox,hInset,vInset);
  94.     InvalRect(&aBox);
  95. }
  96.  
  97. /****************************************************************************************/
  98. pascal void BoxItem(WindowPtr theWindow,short itemNum)
  99. {
  100.     short    aType;
  101.     Rect    theBox;
  102.     Handle    aHandle;
  103.  
  104.     GetDItem(theWindow,itemNum,&aType,&aHandle,&theBox);
  105.     PenNormal();
  106.     ForeColor(blackColor);
  107.     
  108.     FrameRect(&theBox);
  109. }
  110.  
  111. /****************************************************************************************/
  112. pascal void GrayBoxItem(WindowPtr theWindow,short itemNum)
  113. {
  114.     short    aType;
  115.     Rect    theBox;
  116.     Handle    aHandle;
  117.  
  118.     GetDItem(theWindow,itemNum,&aType,&aHandle,&theBox);
  119.     PenNormal(); PenPat(&qd.gray);
  120.     ForeColor(blackColor);
  121.     
  122.     FrameRect(&theBox);
  123.     PenNormal();
  124. }
  125.  
  126. /****************************************************************************************/
  127. void TextParms(short code)
  128. {
  129.     static short txFont,txFace,txSize,txMode;
  130.     
  131.     if (code == kSave) {        /* Save current port's text parameters */
  132.         txFont = qd.thePort->txFont;
  133.         txFace = qd.thePort->txFace;
  134.         txSize = qd.thePort->txSize;
  135.         txMode = qd.thePort->txMode;
  136.     } else {                    /* Restore current port's text parameters */
  137.         TextFont(txFont);
  138.         TextFace(txFace);
  139.         TextSize(txSize);
  140.         TextMode(txMode);
  141.     }
  142. }
  143.